package Demo1;

import java.util.Arrays;
import java.util.Comparator;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2022-10-07
 * Time: 9:56
 */
class Sturdnt {
    public String name;
    public  int score;
    public Sturdnt(String name,int score){
        this.name = name;
        this.score = score;
    }

    @Override
    public String toString() {
        return "Sturdnt{" +
                "name='" + name + '\'' +
                ", score=" + score +
                '}';
    }

}
class ScoreComparator implements Comparator<Sturdnt>{

    @Override
    public int compare(Sturdnt o1, Sturdnt o2) {
        return o1.score -o2.score;
    }
}
class NameComparator implements  Comparator<Sturdnt>{

    @Override
    public int compare(Sturdnt o1, Sturdnt o2) {
        return o1.name.compareTo(o2.name);
    }

}

public class Test1 {
    public static void main(String[] args) {
        Sturdnt[] sturdnts = new Sturdnt[3];
        sturdnts[0] = new Sturdnt("大飞",89);
        sturdnts[1] = new Sturdnt("白糖",90);
        sturdnts[2] = new Sturdnt("武松",99);
        ScoreComparator scoreComparator = new ScoreComparator();
        Arrays.sort(sturdnts,scoreComparator);
        System.out.println(Arrays.toString(sturdnts));
        NameComparator nameComparator = new NameComparator();
        Arrays.sort(sturdnts,nameComparator);
        System.out.println(Arrays.toString(sturdnts));
    }
}
